package edu.scut.ga.reconf;

import static org.junit.Assert.*;

import org.jenetics.CharacterChromosome;
import org.jenetics.CharacterGene;
import org.jenetics.Genotype;
import org.jenetics.util.Array;
import org.jenetics.util.CharSet;
import org.junit.Test;

public class LossFunctionTest {

	@Test
	public void testEvaluate() {
		LossFunction lf = new LossFunction("testData/ieee70cdf.xls");
		final CharSet validCharacters = new CharSet("012");
		final Array<CharacterGene> genes = new Array<CharacterGene>(
		               CharacterGene.valueOf('0', validCharacters),
		               CharacterGene.valueOf('2', validCharacters),
		               CharacterGene.valueOf('2', validCharacters),
		               CharacterGene.valueOf('2', validCharacters),
		               CharacterGene.valueOf('1', validCharacters)
		       );

		Genotype<CharacterGene> genotype = Genotype.valueOf(new CharacterChromosome(genes.toISeq()));
		double res = lf.evaluate(genotype);
		System.out.println("Total loss=" + res);
		assertTrue(res < 1.0E10);
	}

}